#!/usr/bin/env python

import os,sys,yaml,re,shutil
from subprocess import Popen,PIPE
if len(sys.argv) == 1:
  sys.argv.append("default.yml")
  sys.argv.append("daily")

#global variable
config=yaml.load(open(sys.argv[1],'r').read())
TYPE = sys.argv[2] # because of type function
local_dest = config['local_destination']

def copy():
  if not os.path.exists(local_dest):
    os.makedirs(local_dest)
  targets = []
  [targets.extend(config[TYPE][i]) for i in config[TYPE] 
    if re.search('^target',i)]
  for target in targets:
    Popen(['cp','-r',target,local_dest])

  for  

def log(message='',fun=None,isEndPrint=False):
  from datetime import datetime 
  print "[%s] %s %s"%(datetime.now().isoformat(),TYPE,message)
  if callable(fun):
    fun()
  if isEndPrint:
    print "[%s] %s %s end"%(datetime.now().isoformat(),TYPE,message)

from datetime import datetime 


log('copy',copy,True)
#process()
#send()
#clean()
